/* 
   Copyright 2012 Ryne Okimoto

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package tests;

import static org.junit.Assert.*;

import java.io.File;

import model.DataManagerModel;
import manager.FileManager;
import org.junit.Test;

public class DataManagerModelTests {

	@Test
	public void testDataManagerModel() {
		DataManagerModel dm = new DataManagerModel();
		assertNotNull(dm.isDataStructureInitialized());
	}

	@Test
	public void testAddFileManager() {
		DataManagerModel dm = new DataManagerModel();
		assertTrue("Should be true", dm.isDataStructureInitialized() && dm.getDataSetSize() == 0);
		dm.addFileManager("testrecipe", "test", "1 oz beef", "directions", "none", "");
		assertTrue(dm.getDataSetSize() > 0);
		File rf = new File(FileManager.getDefaultRecipePath() + "testrecipe.rcp");
		if(rf.exists()){
			rf.delete();
		}
	}

	@Test
	public void testSetCurrentFileManager() {
		FileManager fm = new FileManager();
		DataManagerModel dm = new DataManagerModel();
		dm.setCurrentFileManager(fm);
		assertTrue(dm.getCurrentFileManager() == fm);
	}

	@Test
	public void testGetCurrentFileManager() {
		testSetCurrentFileManager();
	}

	@Test
	public void testModifyFileManager() {
		FileManager fm = new FileManager("test");
		DataManagerModel dm = new DataManagerModel();
		fm.createRecipe("test", "testing", "2 c sugar", "instructions", "", "tags");
		dm.setCurrentFileManager(fm);
		assertTrue(dm.getCurrentFileManager().getData().getRecipeName().equals("test"));
		
		dm.modifyFileManager("revised", "test", "1 tsp salt", "directions", "none", "");
		assertTrue(dm.getCurrentFileManager().getData().getRecipeName().equals("revised"));
		
		File f = new File(FileManager.getDefaultRecipePath() + "revised.rcp");
		if(f.exists()){
			f.delete();
		}
	}

}
